using System.Threading.Tasks;

namespace EntityKit.Runtime
{
    /// <summary>
    /// 数据序列化接口
    /// </summary>
    public interface IDataSerializer
    {
        /// <summary>
        /// 序列化对象为字符串
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <returns>序列化后的字符串</returns>
        string Serialize(object obj);

        /// <summary>
        /// 异步序列化对象为字符串
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <returns>序列化后的字符串</returns>
        Task<string> SerializeAsync(object obj);

        /// <summary>
        /// 从字符串反序列化对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="data">序列化数据</param>
        /// <returns>反序列化的对象</returns>
        T Deserialize<T>(string data);

        /// <summary>
        /// 异步从字符串反序列化对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="data">序列化数据</param>
        /// <returns>反序列化的对象</returns>
        Task<T> DeserializeAsync<T>(string data);
    }
}